package com.yidiandao.business.ui.widget.view;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;

public class SearchTagView extends AppCompatTextView {

    public static final int SEARCH_TAG_PADDING = 20;

    public static final int TEXT_SIZE = 17;

    public SearchTagView(Context context) {
        this(context, null);
    }

    public SearchTagView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setPadding(dp2px(SEARCH_TAG_PADDING), 0, dp2px(SEARCH_TAG_PADDING), 0);

        setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(TEXT_SIZE));
        setTextColor(Color.parseColor("#f81d5f"));
        setIncludeFontPadding(false);
    }

    public int dp2px(int dp) {
        // px = dp * (dpi / 160)
        DisplayMetrics metrics = getResources().getDisplayMetrics();
        int dpi = metrics.densityDpi;

        return (int) (dp * (dpi / 160f) + 0.5f);
    }


}
